package com.beamfield.controller.api.mb;

import com.beamfield.common.ApiResult;
import com.beamfield.controller.common.MbBaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.service.manage.operator.ManagerInfoService;
import com.beamfield.service.manage.process.ProcessService;
import com.beamfield.service.manage.sys.SuppliesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author chenjj
 * @Description:梁场概况
 * @Date 2018/10/16
 */
@Controller
@RequestMapping(value = "/mb_api/beam")
public class MbBeamController extends MbBaseController{
    private final ManagerInfoService managerInfoService;

    private final SuppliesService suppliesService;

    private final ProcessService processService;

    @Autowired
    public MbBeamController(ManagerInfoService managerInfoService,SuppliesService suppliesService,ProcessService processService){
        this.managerInfoService = managerInfoService;
        this.suppliesService = suppliesService;
        this.processService = processService;
    }

    /**
     * 获取人力资源总览
     * @return
     */
    @RequestMapping(value = "/getPeopleData", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult getPeopleData(HttpServletRequest request){
        Long beamId = super.getLogInfo(request).getBeamId();
        try{
            return managerInfoService.getMbPeopleData(beamId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 获取物资总览
     * @return
     */
    @RequestMapping(value = "/getMaterialData", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult getMaterialData(HttpServletRequest request){
        Long beamId = super.getLogInfo(request).getBeamId();
        try{
            return suppliesService.getMbMaterialData(beamId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }

    /**
     * 获取生产总览
     * @return
     */
    @RequestMapping(value = "/getProduceData", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult getProduceData(HttpServletRequest request){
        Long beamId = super.getLogInfo(request).getBeamId();
        try{
            return processService.getMbProduceData(beamId);
        }catch (Exception e){
            e.printStackTrace();
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), HttpResultEnum.EXCEPTION.getMessage());
        }
    }
}
